package com.fcx.workai.home_module.util;

/**
 * Created by hxh on 2017/6/5.
 */
public class WebLoadHtmlUtils {
    public static String loadHtml(String title, String content)
    {
        return loadHtml(title,content,false,true);
    }

    public static String loadHtml(String title, String content,boolean isShowBg) {


        return loadHtml(title,content,isShowBg,true);
    }


    public static String loadHtml(String title, String content,boolean isShowBg,boolean isautodevice) {

        StringBuilder html = new StringBuilder();
        html.append("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">");
        html.append("<html xmlns=\"http://www.w3.org/1999/xhtml\">");
        html.append("<head>");
        html.append("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />");
        html.append("<meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">");
        html.append("<meta http-equiv=\"Cache-Control\" content=\"no-transform\">");
        if(isautodevice)
                html.append("<meta name=\"viewport\" content=\"width=device-width\">");
        //    html.append("<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no\">");
        html.append("<meta name=\"keywords\" content=\"\">");
        html.append("<title>" + title + "</title>");

        if(isShowBg)
            html.append("<style>html,body {padding:0;margin:0;} body {background-color:#999999} img{margin-bottom:3px}</style>");
        else html.append("<style>img{margin-bottom:3px} html,body {padding:0;margin:0;} </style>");
        html.append("</head>");
        html.append("<body>" + content + "</body>");
        html.append("</html>");
        return html.toString();
    }

    public static String loadHtmlJoinScriptForShowContractInfo(String title, String content) {
        StringBuilder html = new StringBuilder();
        html.append("<!DOCTYPE html>\n" +
                "<html>\n" +
                "<head>\n" +
                "<meta charset='utf-8' />\n" +
                "<link type=\"text/css\" rel=\"stylesheet\" href=\"css/lanrenzhijia.css\" media=\"screen\" />\n" +
                "</head>\n" +
                "<body>");

        html.append("<div id=\"container\">");

        html.append(content);

        html.append("<ul id=\"images\">\n" +
                "    <li>\n" +
                "      <div> <img id=\"img1\" />" +
                "      \n" +
                "      </div>\n" +
                "    </li>\n" +
                "  </ul>");

        html.append("</div>");
        html.append("</body>");

        html.append("<script src='http://www.lanrenzhijia.com/ajaxjs/1.3.2/jquery-1.3.2.min.js'></script>\n" +
                "<script src='js/jqueryui-core-drag.js'></script>\n" +
                "<script type=\"text/javascript\">\n" +
                "function setpath(path)\n" +
                "{\n" +
                "\t$(\"#img1\").remove();\n" +
                "\tnew_obj = $(\"<img id='img1' src='\"+path+\"'/>\");\n" +
                "\t$(\"ul li div\").append(new_obj);\n" +
                "\n" +
                "\t//document.getElementById('img1').src='images/thumbnails/3dOcean_tn.jpg';\n" +
                "\t//$(\"#img1\").attr(\"src\",\"images/thumbnails/3dOcean_tn.jpg\"); \n" +
                "}\n" +
                "</script>\n" +
                "<script type=\"text/javascript\">\t\t\n" +
                "//*\t\n" +
                "\tvar imgs;\n" +
                "\t\t\n" +
                "\t$(document).ready(function () {\n" +
                "\tvar drag = {};\n" +
                "\t\t$('h1').remove();\n" +
                "\t\t\n" +
                "\t\n" +
                "\t\timgs = $(\"#images li\");\n" +
                "\n" +
                "\t\timgs.draggable({ \n" +
                "\t\t\tstack : { group : '#images li', min : 1},\n" +
                "\t\t\tstart : function () {\n" +
                "\t\t\t\t$this = $(this);\n" +
                "\t\t\t\tif($this.attr('id') === 'instructions') { $this.fadeOut().remove(); }\n" +
                "\t\t\t\t\n" +
                "\t\t\t\timgs.each(function () {\n" +
                "\t\t\t\t\tvar $this = $(this);\n" +
                "\t\t\t\t\tif($this.width() !== 256) {\n" +
                "\t\t\t\t\t\t$this.stop().animate({width : 256 }).removeClass('top');\n" +
                "\t\t\t\t\t}\n" +
                "\t\t\t\t});\n" +
                "\t\t\t\t\n" +
                "\t\t\t\tdrag.startTime = new Date();\n" +
                "\t\t\t\tdrag.startPos = $this.position();\n" +
                "\t\t\t},\n" +
                "\t\t\tstop : function () {\n" +
                "\t\t\t\tvar $this = $(this), top, left, time;\n" +
                "\t\t\t\tdrag.endTime = new Date();\n" +
                "\t\t\t\tdrag.endPos = $this.position();\n" +
                "\t\t\t\tdrag.leftOffset = drag.endPos.left - drag.startPos.left;\n" +
                "\t\t\t\tdrag.topOffset  = drag.endPos.top  - drag.startPos.top;\n" +
                "\n" +
                "\t\t\t\ttime = (drag.endTime.getTime() - drag.startTime.getTime()) /60;\n" +
                "\t\t\t\t\n" +
                "\t\t\t\ttop  = (drag.topOffset / time).toString();\n" +
                "\t\t\t\tleft = (drag.leftOffset / time).toString();\n" +
                "\t\t\t\t\n" +
                "\t\t\t\t$this.animate({\n" +
                "\t\t\t\t\ttop : '+=' + top, \n" +
                "\t\t\t\t\tleft: '+=' + left \n" +
                "\t\t\t\t});\n" +
                "\t\t\t}\n" +
                "\t\t});\n" +
                "\n" +
                "\t\timgs.click(function () {\n" +
                "\t\t\tvar $this = $(this);\n" +
                "\t\t\n" +
                "\t\t\tif ($this.attr('id') == 'instructions') {\n" +
                "\t\t\t\t$this.fadeOut().remove();\n" +
                "\t\t\t}\n" +
                "\t\t\telse {\n" +
                "\t\t\t\tif($this.width() !== 256) {\n" +
                "\t\t\t\t\t$this.stop().animate({width : 256 }).removeClass('top');\n" +
                "\t\t\t\t}\n" +
                "\t\t\t\telse {\n" +
                "\t\t\t\t\tif (!($this.find('.info').length)) {\n" +
                "\t\t\t\t\t\t$.ajax({\n" +
                "\t\t\t\t\t\t\turl : $this.find('a').attr('href'),\n" +
                "\t\t\t\t\t\t\tdataType : 'html',\n" +
                "\t\t\t\t\t\t\tsuccess : function (data) {\n" +
                "\t\t\t\t\t\t\t\tvar $d = $(data),\n" +
                "\t\t\t\t\t\t\t\t\thead = $d.filter('h1'),\n" +
                "\t\t\t\t\t\t\t\t\tpara = $d.filter('p');\n" +
                "\t\t\t\t\t\t\t\t\t\n" +
                "\t\t\t\t\t\t\t\t$this.children('div').append('<div class=\"info\"></div>').find(\".info\").append(head, para);\n" +
                "\t\t\t\t\t\t\t},\n" +
                "\t\t\t\t\t\t\terror : function () {\n" +
                "\t\t\t\t\t\t\t\tvar msg = '<h1>Oops!</h1><p>It looks like there been a problem; we can\\'t get this info right now.</p>';\n" +
                "\t\t\t\t\t\t\t\t$this.children('div').append('<div class=\"info\"></div>').find(\".info\").html(msg);\n" +
                "\t\t\t\t\t\t\t}\n" +
                "\t\t\t\t\t\t});\n" +
                "\t\t\t\t\t}\n" +
                "\t\t\t\t\t$this.css({'zIndex' :8 })\n" +
                "\t\t\t\t\t\t\t .stop()\n" +
                "\t\t\t\t\t\t\t .animate({ width : 512})\n" +
                "\t\t\t\t\t\t\t .addClass('top')\n" +
                "\t\t\t\t\t\t\t\t.siblings().removeClass('top')\n" +
                "\t\t\t\t\t\t\t\t\t\t   .stop()\n" +
                "\t\t\t\t\t\t\t\t\t\t   .animate({width : 256})\n" +
                "\t\t\t\t\t\t\t\t\t\t\t\t.filter(function () { return $(this).css('zIndex') >= '8' }).css({'zIndex' : 7});\n" +
                "\t\t\t\t}\n" +
                "\t\t\t}\n" +
                "\t\t\treturn false;\n" +
                "\t\t});\n" +
                "\t\t\n" +
                "\t});\n" +
                "\n" +
                "$(window).load(function () {\n" +
                "\t$w = $(window);\n" +
                "\timgs.css({\n" +
                "\t\t\tposition : 'absolute',\n" +
                "\t\t\tleft : $w.width() / 2 - imgs.width(),\n" +
                "\t\t\ttop  : $w.height() / 2- imgs.height()\n" +
                "\t\t});\n" +
                "\tfor(var i = 0; imgs[i]; i++ ) {\n" +
                "\t\t$(imgs[i]).animate({\n" +
                "\t\t\t\tleft : '+=' + Math.random()*150,\n" +
                "\t\t\t\ttop  : '+=' + Math.random()*150\n" +
                "\t\t\t});\n" +
                "\t}\n" +
                "});//*/\n" +
                "\n" +
                "</script>");

        html.append("</html>");
        return html.toString();
    }

}
